package canteen.sys.view.individual;

import canteen.sys.model.entity.BillDetail;
import canteen.sys.model.entity.BillMaster;
import canteen.sys.model.entity.DepartmentMaster;
import canteen.sys.model.entity.ItemMaster;
import canteen.sys.model.entity.ItemTypeMaster;
import canteen.sys.model.entity.LoginMaster;
import canteen.sys.model.generic.HibernateDAOFactory;
import canteen.sys.view.ActionView;
import canteen.sys.view.ComboboxRecInfo;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;

public class BillEntry extends javax.swing.JInternalFrame implements ActionView<ItemMaster> {

    HibernateDAOFactory hibernateDAOFactory = HibernateDAOFactory.getInstance();
    Vector data = new Vector();
    Vector Column;
    DefaultTableModel model;
    DefaultTableModel modelSelected;
    LoginMaster Lm;
    List<ItemMaster> listItem;

    public BillEntry(LoginMaster lm) {
        Lm = lm;
        initComponents();
        model = (DefaultTableModel) tbItems.getModel();
        modelSelected = (DefaultTableModel) tableItemDetails.getModel();
        getListItemType();
        //  getListItem();
        if (cbCategory.getItemCount() > 0) {
            ComboboxRecInfo<ItemTypeMaster> listInfo = (ComboboxRecInfo<ItemTypeMaster>) cbCategory.getSelectedItem();
            if (listItem != null) {
                listItem.clear();
            }
            listItem = hibernateDAOFactory.getItemMasterDAO()
                    .findAllByItemTypeIdAndStatus(listInfo.getKeyData().getItemTypeId(), true);
            showList(listItem);
        }
        listSelectionListener();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        editorLayer = new javax.swing.JLayeredPane();
        jLabel1 = new javax.swing.JLabel();
        txtNo = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtCoupenNo = new javax.swing.JTextField();
        calDate = new org.freixas.jcalendar.JCalendarCombo();
        calCoupenDate = new org.freixas.jcalendar.JCalendarCombo();
        itemDetailLayer = new javax.swing.JLayeredPane();
        txtItemQty = new javax.swing.JTextField();
        txtItemRate = new javax.swing.JTextField();
        btAdd = new javax.swing.JButton();
        btRemove = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableItemDetails = new javax.swing.JTable();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        txtTotal = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        cbCategory = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tbItems = new javax.swing.JTable();
        txtItemName = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        actionLayer = new javax.swing.JLayeredPane();
        btSave = new javax.swing.JButton();
        btCancel = new javax.swing.JButton();

        setClosable(true);
        setTitle("Add new bill");

        editorLayer.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        editorLayer.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N

        jLabel1.setText("No");
        jLabel1.setBounds(10, 20, 30, 14);
        editorLayer.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        txtNo.setEnabled(false);
        txtNo.setBounds(100, 20, 170, 20);
        editorLayer.add(txtNo, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel5.setText("Date");
        jLabel5.setBounds(10, 50, 50, 14);
        editorLayer.add(jLabel5, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel6.setText("Coupen No");
        jLabel6.setBounds(10, 80, 90, 14);
        editorLayer.add(jLabel6, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel7.setText("Coupen Date");
        jLabel7.setBounds(10, 110, 90, 14);
        editorLayer.add(jLabel7, javax.swing.JLayeredPane.DEFAULT_LAYER);
        txtCoupenNo.setBounds(100, 80, 110, 20);
        editorLayer.add(txtCoupenNo, javax.swing.JLayeredPane.DEFAULT_LAYER);

        calDate.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "MM/dd/yyyy" }));
        calDate.setDateFormat(new SimpleDateFormat("MM/dd/yyyy"));
        calDate.setBounds(100, 50, 110, 20);
        editorLayer.add(calDate, javax.swing.JLayeredPane.DEFAULT_LAYER);

        calCoupenDate.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "MM/dd/yyyy" }));
        calCoupenDate.setDate(new java.util.Date(1348094944000L));
        calCoupenDate.setDateFormat(new SimpleDateFormat("MM/dd/yyyy"));
        calCoupenDate.setBounds(100, 110, 110, 20);
        editorLayer.add(calCoupenDate, javax.swing.JLayeredPane.DEFAULT_LAYER);

        itemDetailLayer.setBorder(javax.swing.BorderFactory.createTitledBorder("Item Details"));
        txtItemQty.setBounds(230, 240, 40, 20);
        itemDetailLayer.add(txtItemQty, javax.swing.JLayeredPane.DEFAULT_LAYER);

        txtItemRate.setEditable(false);
        txtItemRate.setBounds(280, 240, 110, 20);
        itemDetailLayer.add(txtItemRate, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btAdd.setText("Add");
        btAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAddActionPerformed(evt);
            }
        });
        btAdd.setBounds(400, 210, 80, 23);
        itemDetailLayer.add(btAdd, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btRemove.setText("Remove");
        btRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRemoveActionPerformed(evt);
            }
        });
        btRemove.setBounds(400, 240, 80, 23);
        itemDetailLayer.add(btRemove, javax.swing.JLayeredPane.DEFAULT_LAYER);

        tableItemDetails.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "No.", "ItemName", "Qty", "Rate", "Amount"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tableItemDetails);

        jScrollPane1.setBounds(10, 270, 460, 150);
        itemDetailLayer.add(jScrollPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel9.setText("Item Name");
        jLabel9.setBounds(80, 220, 60, 14);
        itemDetailLayer.add(jLabel9, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel10.setText("Item Rate");
        jLabel10.setBounds(300, 220, 60, 14);
        itemDetailLayer.add(jLabel10, javax.swing.JLayeredPane.DEFAULT_LAYER);

        txtTotal.setEnabled(false);
        txtTotal.setBounds(370, 440, 110, 20);
        itemDetailLayer.add(txtTotal, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel12.setText("Total");
        jLabel12.setBounds(310, 440, 50, 14);
        itemDetailLayer.add(jLabel12, javax.swing.JLayeredPane.DEFAULT_LAYER);

        cbCategory.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbCategoryItemStateChanged(evt);
            }
        });
        cbCategory.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbCategoryActionPerformed(evt);
            }
        });
        cbCategory.setBounds(70, 20, 170, 20);
        itemDetailLayer.add(cbCategory, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel2.setText("Item Type");
        jLabel2.setBounds(10, 20, 90, 20);
        itemDetailLayer.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        tbItems.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(tbItems);

        jScrollPane2.setBounds(12, 50, 460, 140);
        itemDetailLayer.add(jScrollPane2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        txtItemName.setEnabled(false);
        txtItemName.setBounds(79, 240, 140, 20);
        itemDetailLayer.add(txtItemName, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel11.setText("Item Qty");
        jLabel11.setBounds(230, 220, 60, 14);
        itemDetailLayer.add(jLabel11, javax.swing.JLayeredPane.DEFAULT_LAYER);

        actionLayer.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        btSave.setText("Save");
        btSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSaveActionPerformed(evt);
            }
        });
        btSave.setBounds(600, 10, 80, 23);
        actionLayer.add(btSave, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btCancel.setText("Cancel");
        btCancel.setBounds(680, 10, 80, 23);
        actionLayer.add(btCancel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(actionLayer)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(editorLayer, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(itemDetailLayer, javax.swing.GroupLayout.PREFERRED_SIZE, 483, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(editorLayer, javax.swing.GroupLayout.DEFAULT_SIZE, 486, Short.MAX_VALUE)
                    .addComponent(itemDetailLayer))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(actionLayer, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cbCategoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbCategoryActionPerformed
        // TODO add your handling code here:
        if (cbCategory.getItemCount() > 0) {
            ComboboxRecInfo<ItemTypeMaster> combobox = (ComboboxRecInfo<ItemTypeMaster>) cbCategory.getSelectedItem();
            List<ItemMaster> listI = hibernateDAOFactory.getItemMasterDAO().findAllByItemTypeIdAndStatus(combobox.getKeyData().getItemTypeId(), true);
            showList(listI);
        } else {
            JOptionPane.showMessageDialog(this, "No Item Type to select!");
        }
    }//GEN-LAST:event_cbCategoryActionPerformed

    private void cbCategoryItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbCategoryItemStateChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_cbCategoryItemStateChanged

    private void btAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddActionPerformed
        // TODO add your handling code here:
        try {
            int indexItem = tbItems.getSelectedRow();
            if (Integer.parseInt(tbItems.getValueAt(indexItem, 1).toString()) > 0) {

                if (txtItemQty.getText().equals("") || txtItemQty.getText().equals("(Enter Quantity Sale)")) {
                    txtItemQty.setText("Quantity not null!");
                    txtItemQty.requestFocus();
                    txtItemQty.selectAll();
                    return;
                }

                String s2 = txtItemQty.getText();
                if (!s2.matches("^(\\d*)$")) {
                    txtItemQty.setText("Quantity not is number!!");
                    txtItemQty.requestFocus();
                    txtItemQty.selectAll();
                    return;
                }

                Column = new Vector();
                Column.add("No.");
                Column.add("ItemName");
                Column.add("Qty");
                Column.add("Rate");
                Column.add("Amount");

                int qty = 0;
                boolean check = false;
                double rate = 0;

//                for (int i = 0; i < tableItemDetails.getRowCount(); i++) {
//                    if (im.getKeyData().getItemId() == tableItemDetails.getValueAt(i, 0)) {
//                        qty = Integer.parseInt(tableItemDetails.getValueAt(i, 2).toString());
//                        model.removeRow(i);
//                    }
//                }

//                ItemMaster imd = im.getKeyData();
                for (int j = 0; j < tableItemDetails.getModel().getRowCount(); j++) {
                    if (tableItemDetails.getValueAt(j, 1).equals(txtItemName.getText())) {
                        ItemMaster item = null;
                        for (ItemMaster im : listItem) {
                            if (im.getItemName().equals(txtItemName.getText())) {
                                item = im;
                                break;
                            }
                        }
                        qty = item.getQuantity();
                        rate = item.getItemRate();
                        item.setQuantity(Integer.parseInt(txtItemQty.getText()) + qty);
//                        Vector vRow1 = new Vector();
//                        vRow1.add(item.getItemId());
//                        vRow1.add(item.getItemName());
//                        vRow1.add(item.getQuantity());
//                        vRow1.add(item.getItemRate());
//
//                        if (qty == 0) {
//                            vRow1.add("$0");
//                        } else {
//
//                            vRow1.add("$" + item.getQuantity() * item.getItemRate());
//                        }
                        tableItemDetails.setValueAt(qty, j, 2);
                        tableItemDetails.setValueAt("$" + item.getQuantity() * item.getItemRate(), j, 4);
//                data.add(vRow1);
//                model = new DefaultTableModel(data, Column);
//                tableItemDetails.setModel(model);
                        break;
                    } else {
                        check = true;
                    }
                }
                if (check == true) {
                    ItemMaster im = listItem.get(listItem.size() - 1 - indexItem);
                    modelSelected.insertRow(tableItemDetails.getRowCount() - 1, new Object[]{tableItemDetails.getRowCount(),
                                im.getItemName(), im.getQuantity(),
                                im.getItemRate(),
                                "$" + im.getQuantity() * im.getItemRate()});
                }
            }

            double total = 0;
            for (int i = 0; i < tableItemDetails.getRowCount(); i++) {
                Vector vRow = (Vector) data.get(i);
                total += Double.parseDouble(vRow.get(4).toString().substring(1));
            }
            txtTotal.setText(total + "");

        } catch (NumberFormatException ex) {
        }
    }//GEN-LAST:event_btAddActionPerformed

    private void btRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRemoveActionPerformed
        // TODO add your handling code here:
        int row = tableItemDetails.getSelectedRow();
        if (row < 0) {
            JOptionPane.showMessageDialog(this, "Choose a order detail!");
            return;
        }
        model.removeRow(row);
    }//GEN-LAST:event_btRemoveActionPerformed

    private void btSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSaveActionPerformed
        // TODO add your handling code here:

        BillMaster bm = new BillMaster();
        bm.setbDate(new Date(calDate.getCalendar().getTimeInMillis()));
        bm.setCoupenDate(new Date(calCoupenDate.getCalendar().getTimeInMillis()));
        bm.setCoupenNo(txtCoupenNo.getText());
        DepartmentMaster dm = ((ComboboxRecInfo<DepartmentMaster>) cbCategory.getSelectedItem()).getKeyData();
        bm.setbCategory(dm.getDepartmentName());
        bm.setEmployeeMaster(null);
        bm.setLoginMaster(Lm);
        bm.setDepartment(dm);
        bm.setStatus(0);
        if (validObject(bm)) {
            BillMaster BillMasterResult = hibernateDAOFactory.getBillMasterDAO().makePersistent(bm);
            JOptionPane.showMessageDialog(this, "Insert bill ok!");
            if (BillMasterResult.getbId() != 0) {
                for (int i = 0; i < tableItemDetails.getRowCount(); i++) {
                    Vector vRow = (Vector) data.get(i);
                    ItemMaster im = new ItemMaster(Integer.parseInt(vRow.get(0).toString()), vRow.get(1).toString(),
                            Double.parseDouble(vRow.get(3).toString()),
                            isMaximum);
                    BillDetail bd = new BillDetail(BillMasterResult, im, im.getItemId(), Integer.parseInt(vRow.get(2).toString()), Double.parseDouble(vRow.get(4).toString()));
                    hibernateDAOFactory.getBillDetailDAO().makePersistent(bd);
                }
            }
        }
    }//GEN-LAST:event_btSaveActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLayeredPane actionLayer;
    private javax.swing.JButton btAdd;
    private javax.swing.JButton btCancel;
    private javax.swing.JButton btRemove;
    private javax.swing.JButton btSave;
    private org.freixas.jcalendar.JCalendarCombo calCoupenDate;
    private org.freixas.jcalendar.JCalendarCombo calDate;
    private javax.swing.JComboBox cbCategory;
    private javax.swing.JLayeredPane editorLayer;
    private javax.swing.JLayeredPane itemDetailLayer;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable tableItemDetails;
    private javax.swing.JTable tbItems;
    private javax.swing.JTextField txtCoupenNo;
    private javax.swing.JTextField txtItemName;
    private javax.swing.JTextField txtItemQty;
    private javax.swing.JTextField txtItemRate;
    private javax.swing.JTextField txtNo;
    private javax.swing.JTextField txtTotal;
    // End of variables declaration//GEN-END:variables

//    private void getListItem() {
//        if (cbCategory.getItemCount() > 0) {
//            ComboboxRecInfo<ItemMaster> combobox;
//            combobox = (ComboboxRecInfo<ItemMaster>) cbCategory.getSelectedItem();
//            List<ItemMaster> listItem = hibernateDAOFactory.getItemMasterDAO().findAllByItemTypeIdAndStatus(combobox.getKeyData().getItemType().getItemTypeId(), true);
//            for (ItemMaster itemMaster : listItem) {
//            }
////            if (listItem.size() > 0) {
////
////                for (ItemMaster item : listItem) {
////                    ComboboxRecInfo<ItemMaster> combobox = new ComboboxRecInfo<>();
////                    combobox.setName(item.getItemName());
////                    combobox.setKeyData(item);
////                    cbItemName.addItem(combobox);
////                }
////            }
//        } else {
//            JOptionPane.showMessageDialog(this, "No ItemType to select!", "Warning", JOptionPane.WARNING_MESSAGE);
//        }
//    }
    private void getListItemType() {
        List<ItemTypeMaster> listItemType = hibernateDAOFactory.getItemTypeMasterDAO().findAllByStatus(true);
        if (listItemType.size() > 0) {

            for (ItemTypeMaster itm : listItemType) {
                ComboboxRecInfo<ItemTypeMaster> combobox = new ComboboxRecInfo<>();
                combobox.setName(itm.getItemTypeName());
                combobox.setKeyData(itm);
                cbCategory.addItem(combobox);
            }
        }
    }

    public boolean validObject(BillMaster object) {
        boolean check = true;
        if (object.getCoupenDate() == null) {
            JOptionPane.showMessageDialog(this, "CoupenDate must input!");
            return false;
        }
        if (object.getbDate() == null) {
            JOptionPane.showMessageDialog(this, "CoupenDate must input!");
            return false;
        }
        if (object.getCoupenNo().equals("") || object.getCoupenNo() == null) {
            JOptionPane.showMessageDialog(this, "CoupenNo must input!");
            txtCoupenNo.setText("not null!");
            txtCoupenNo.requestFocus();
            txtCoupenNo.selectAll();
            return false;
        }
        if (object.getDepartment() == null) {
            JOptionPane.showMessageDialog(this, "getDepartment must input!");
            return false;
        }
        if (object.getLoginMaster().equals("")) {
            JOptionPane.showMessageDialog(this, "getLoginMaster must input!");
            return false;
        }
        return check;
    }

    @Override
    public void deleteRow(int index) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void updateRow(ItemMaster row, int index) {
        try {
            tbItems.setValueAt(row.getItemName(), index, 0);
            tbItems.setValueAt(row.getQuantity(), index, 1);
            tbItems.setValueAt(row.getItemRate(), index, 2);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error: \n" + ex.getMessage());
        }
    }

    @Override
    public void addRow(ItemMaster row, boolean posion) {
        model.insertRow(0, new Object[]{row.getItemName(), row.getQuantity(), "$" + row.getItemRate()});
    }

    @Override
    public final void showList(List<ItemMaster> list) {
        model.setDataVector(null, new Object[]{"Item Name", "Qty", "Rate"});
        if (listItem != null) {
            listItem.clear();
        }
        listItem = list;
        for (ItemMaster itemMaster : list) {
            addRow(itemMaster, true);
        }
    }

    @Override
    public void showDetail(ItemMaster object) {
        txtItemName.setText(object.getItemName());
        txtItemRate.setText("$" + object.getItemRate());
    }

    @Override
    public ItemMaster getObject(int index) {
        ItemMaster itemMaster;
        itemMaster = listItem.get(listItem.size() - 1 - index);
        return itemMaster;
    }

    @Override
    public void setObject(ItemMaster object) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean validObject(ItemMaster object) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public final void listSelectionListener() {
        tbItems.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                int rowSelected = tbItems.getSelectedRow();
                showDetail(getObject(rowSelected));
            }
        });
    }
}
